package com.tsinghuabigdata.edu.ddmath.util;

import java.util.HashSet;
import java.util.Set;

/**
 * <p>
 * Created by yanshen@tsinghuabigdata.com on 2015/11/3.
 * </p>
 *
 * @author yanshen@tsinghuabigdata.com
 * @version V1.0
 * @packageName: com.tsinghuabigdata.edu.ddmath
 * @createTime: 2015/11/3 15:06
 */
public class LicenseUtils {

    /**
     * 返回License数组
     * @param files
     * @return
     */
    public static String[] getLicenseByOfflineFiles(String[] files){
        Set<String> licenses = new HashSet<String>();
        if(files != null && files.length > 0){
            for (String file : files) {
                if(file != null){
                    licenses.add(getLicenseByFile(file));
                }
            }
        }
        return licenses.toArray(new String[licenses.size()]);
    }

    /**
     * 返回格式noteId.pageId
     * @param file
     * @return
     */
    public static String getLicenseByFile(String file) {
        String[] segment = file.split("_");
        if(segment.length == 5){
            return segment[2] + "." + segment[3];
        }
        return "";
    }

    /**
     * 判断文件是否和license匹配
     * @param file
     * @param license
     * @return
     */
    public static boolean equalsLicense(String file, String license){
        return getLicenseByFile(file).equals(license);
    }

}
